package it.evento.utils.genpage;

import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Ilo
 */
public class BlogPost {
    
    private String title;
    private String content;
    private String link;
    private String author;
    private boolean readMore;
    private boolean hasMetadata;
    private LinkedList<String> categories;
    private long stars;
    private long ratesNumber;
    private String id;

    public BlogPost() {
        resetAll();
    }

    public BlogPost setTitle(String title) {
        this.title = title;
        return this;
    }
    
    public BlogPost setContent(String content) {
        this.content = content;
        return this;
    }

    public BlogPost setLink(String link) {
        this.link = link;
        return this;
    }

    public BlogPost setAuthor(String author) {
        this.author = author;
        return this;
    }

    public BlogPost setReadMore(boolean readMore) {
        this.readMore = readMore;
        return this;
    }

    public BlogPost hadMetadata(boolean hasit) {
        this.hasMetadata = hasit;
        return this;
    }
    
    public BlogPost setCategories(List<String> categories) {
        this.categories.addAll(categories);
        return this;
    }
    
    public BlogPost addCategory(String category) {
        this.categories.add(category);
        return this;
    }
    
    public BlogPost setStars(long stars) {
        this.stars = stars;
        return this;
    }
    
    public BlogPost setRatesNumber(long ratesNumber) {
        this.ratesNumber = ratesNumber;
        return this;
    }
    
    public BlogPost setID(String id) {
        this.id = id;
        return this;
    }
    
    public String print() {
        String ret = "";
        
        ret += "<article class='evento-post evento-article'>";
            ret += "<div class='evento-postmetadataheader'>";
                if(this.title != null) {
                    ret += "<h2 class='evento-postheader'>";
                        if(this.link != null)
                            ret += "<a href='" + this.link + "'>" + this.title + "</a>";
                        else
                            ret += this.title;
                    ret += "</h2>";
                }
            ret += "</div>";
            
            if(this.hasMetadata) {
                ret += "<div class='evento-postheadericons evento-metadata-icons'>";
                    ret += "<span class='evento-postdateicon'></span>";
                    ret += " | <span class='evento-postauthoricon'>" + this.author + "</span>";
                    ret += " | <span class='evento-postpdficon'></span>";
                    ret += " | <span class='evento-postprinticon'></span>";
                    ret += " | <span class='evento-postemailicon'></span>";
                    ret += " | <span class='evento-postediticon'></span>";
                ret += "</div>";
            }
            
            if(this.stars != -1) {
                ret += "<div class='evento evento-metadata-icons'>";
                    ret += "<span class='evento-staricon' id='starsfor-" + this.id + "' data-score='" + this.stars + "'></span>";
                    ret += "<span id='votesfor-" + this.id + "'>" + this.ratesNumber + " vot" + (this.ratesNumber==1 ? "o" : "i") + ".</span>";
                ret += "</div>";
            }
                
            ret += "<div class='evento-postcontent evento-postcontent-0 clearfix'>";
                ret += "<div class='evento-content-layout'>";
                    ret += "<div class='evento-content-layout-row'>";
                        ret += "<div class='evento-layout-cell layout-item-0' style='width: 100%'>";
                            ret += this.content;
                        ret += "</div>";
                    ret += "</div>";
                ret += "</div>";
                ret += "<br>";
                if(this.readMore)
                    ret += "<a href='" + this.link + "'>Leggi tutto...</a>";
            ret += "</div>";
            
            if(!this.categories.isEmpty()) {
                ret += "<div class='evento-postfootericons evento-metadata-icons'>";
                    ret += "<span class='evento-postcategoryicon'>Categorie: " + this.categories + "</span>";
                ret += "</div>";
            }
            
        ret += "</article>";
        
        resetAll();
        
        return ret;
    }
    
    private void resetAll() {
        this.title = null;
        this.content = "";
        this.link = null;
        this.author = null;
        this.readMore = false;
        this.hasMetadata = false;
        this.categories = new LinkedList<>();
        this.stars = -1;
        this.ratesNumber = 0;
        this.id = null;
    }
    
}
